package com.buyouchina.web.action.product;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import org.springframework.stereotype.Controller;

import com.buyouchina.bean.PageView;
import com.buyouchina.bean.product.Category;
import com.buyouchina.bean.product.Product;
import com.buyouchina.service.product.CategoryService;
import com.buyouchina.service.product.ProductSearchService;
import com.buyouchina.web.action.BaseAction;

/**
 * 货品全文检索
 */
@Controller("ProductQuery")
public class ProductQueryAction extends BaseAction {
	
	private static final long serialVersionUID = -3033712845726932687L;
	private String word;
	@Resource ProductSearchService productSearchService;
	@Resource(name = "categoryServiceBean")
	private CategoryService categoryService;
	
	private List<Category> categoryList = new ArrayList<Category>();

	public String getWord() {
		return word;
	}

	public void setWord(String word) {
		this.word = word;
	}
	
	public String execute() {
		PageView<Product> pageView = new PageView<Product>(12,this.getPage());
		pageView.setQueryResult(productSearchService.search(this.getWord(), 
				pageView.getFirstResult(), pageView.getMaxresult()));		
		request.setAttribute("pageView", pageView);
		setCategoryList(categoryService.getScrollData().getResultlist());
		return "success";
	}

	public void setCategoryList(List<Category> categoryList) {
		this.categoryList = categoryList;
	}

	public List<Category> getCategoryList() {
		return categoryList;
	}


}
